package cn.smilefox.controller;

import cn.smilefox.domain.Role;
import cn.smilefox.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;


@RequestMapping("/role")
@Controller
public class RoleController {

    @Autowired
    private RoleService roleService;

    @RequestMapping("/list")
    public ModelAndView list(){
        ModelAndView modelAndView = new ModelAndView();

        List<Role> roleList  = roleService.list();
        //设置模型
        modelAndView.addObject("roleList",roleList);
        System.out.println("ref");
        System.out.println(roleList);
        //设置视图
        modelAndView.setViewName("userrole-list");

        return modelAndView;
    }


    @RequestMapping("/save")
    public String save(Role role){

        roleService.save(role);

        return "redirect:/role/list";

    }

}
